﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class HomePage_PrintWholeZBRecord : System.Web.UI.Page
{
    int PWZBRProjectid;
    protected void Page_Load(object sender, EventArgs e)
    {
        string sql;
        string count = "";


        PWZBRProjectid = SysFun.ToInt(SysFun.IsSQL(MsgBox.JieMi_Decrypt(Request.QueryString["pid"])));
        Db db = new Db();
        System.Data.IDataReader dr;
        sql = "Select count(*) as cun From Show Where ShowProject=" + PWZBRProjectid.ToString() + " And ShowSort='2' ";//是否发布
        dr = db.DataReader(sql);
        while (dr.Read())
        {
            count = dr["cun"].ToString();
        }
        dr.Close();
        dr.Dispose();
        db.Close();
        if (count != "0")
        {
            showGridView();
        }
        else
        {
            Response.Write("<script>window.location.href='../HomePage/Default.aspx'</script>");

        }
    }

    public void showGridView()
    {
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "zbgs" + PWZBRProjectid.ToString();
        dbPage.Key = "goodsid";
        dbPage.Where = strConditions;                        //
        dbPage.SelectField = " goodsid,productname,medicinemodel,outlookc,unit,factor,SCNAME,TBRNAME,RetailPrice,memo4,bidprice";                             //可以不设，默认为“*”


        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 20;                                                //Request.QueryString["PS"]);
        dbPage.OrderBy = "goodsid,bidtableid,productname";
        System.Data.IDataReader dr = dbPage.ExecuteReader(60);
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        db.Close();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键



    }

    public string fctConditions()
    {
        string ProductName, NameTB, NameSC, Goodsid = "";

        ProductName = txtProductName.Text.Trim();
        NameTB = txtNameTB.Text.Trim();

        NameSC = txtNameSC.Text.Trim();

        if (SysFun.IsNumeric(goodsidtext.Text))
        {
            Goodsid = SysFun.ToLong(goodsidtext.Text).ToString();
        }
        string strtemp = "";
        strtemp = "";

        if (ProductName != "")
        {
            strtemp += " ProductName like '%" + ProductName + "%' And";
        }
        if (NameTB != "")
        {
            strtemp += " TBRNAME like '%" + NameTB + "%' And";
        }

        if (NameSC != "")
        {
            strtemp += " SCNAME like '%" + NameSC + "%' And";
        }

        if (Goodsid != "")
        {
            strtemp += " Goodsid like '%" + Goodsid + "%' And";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }

        return strtemp;

    }

}
